# All rights reserved.
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=mt7915
P4REV:=
PKG_VERSION:=TEST
PKG_SOURCE:=mt7915_20220907-9b15d0.tar.xz
PKG_SOURCE_URL:=
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)_mt_wifi
PKG_KCONFIG:= \
	AP_SUPPORT \
	RT_FIRST_CARD \
	RT_SECOND_CARD \
	RT_FIRST_IF_RF_OFFSET \
	RT_SECOND_IF_RF_OFFSET \
	MT_WIFI \
	WIFI_BASIC_FUNC \
	MT_WIFI_PATH \
	FIRST_IF_NONE \
	FIRST_IF_EEPROM_FLASH \
	FIRST_IF_EEPROM_EFUSE \
	RT_FIRST_CARD_EEPROM \
	SECOND_IF_NONE \
	SECOND_IF_EEPROM_FLASH \
	SECOND_IF_EEPROM_PROM \
	SECOND_IF_EEPROM_EFUSE \
	RT_SECOND_CARD_EEPROM \
	MULTI_INF_SUPPORT \
	WIFI_BASIC_FUNC \
	WIRELESS_EXT \
	WEXT_SPY \
	WEXT_PRIV \
	DOT11_N_SUPPORT \
	DOT11_VHT_AC \
	DOT11_HE_AX \
	CFG_SUPPORT_FALCON_MURU \
	CFG_SUPPORT_FALCON_TXCMD_DBG \
	CFG_SUPPORT_FALCON_SR \
	CFG_SUPPORT_FALCON_PP \
	WIFI_DRIVER \
	G_BAND_256QAM_SUPPORT \
	BRCM_256QAM_SUPPORT \
	ICAP_SUPPORT \
	MT_AP_SUPPORT \
	BACKGROUND_SCAN_SUPPORT \
	SMART_CARRIER_SENSE_SUPPORT \
	SCS_FW_OFFLOAD \
	THERMAL_PROTECT_SUPPORT \
	MT_DFS_SUPPORT \
	HDR_TRANS_TX_SUPPORT \
	CHIP_MT7615E \
	HDR_TRANS_RX_SUPPORT \
	DBDC_MODE \
	MULTI_PROFILE_SUPPORT \
	DEFAULT_5G_PROFILE \
	SUPPORT_DYNAMIC_TXOP \
	WSC_INCLUDED \
	MT_STA_SUPPORT \
	WSC_V2_SUPPORT \
	DOT11W_PMF_SUPPORT \
	PASSPOINT_R2 \
	TXBF_SUPPORT \
	IGMP_SNOOP_SUPPORT \
	RATE_ADAPTION \
	RATE_ADAPT_AGBS_SUPPORT \
	RTMP_FLASH_SUPPORT \
	ATE_SUPPORT \
	WLAN_SERVICE \
	UAPSD \
	RLT_MAC \
	RLT_BBP \
	RLT_RF \
	RTMP_MAC \
	RTMP_BBP \
	RTMP_RF \
	RTMP_PCI_SUPPORT \
	RTMP_USB_SUPPORT \
	RTMP_RBUS_SUPPORT \
	WIFI_MODE_AP \
	WIFI_MODE_STA \
	WIRELESS_EXT \
	WEXT_SPY \
	WEXT_PRIV \
	WDS_SUPPORT \
	MBSS_SUPPORT \
	APCLI_SUPPORT \
	APCLI_CERT_SUPPORT \
	APCLI_CONNECTION_TRIAL \
	MAC_REPEATER_SUPPORT \
	RALINK_RT6352 \
	RALINK_MT7620 \
	RALINK_MT7603E \
	CON_WPS_SUPPORT \
	VOW_SUPPORT \
	BAND_STEERING \
	TXOP_ARBITER \
	CFG_SUPPORT_DYNAMIC_TXOP \
	WIFI_MODE_BOTH \
	WIFI_RLT_MAC \
	RLT_MAC \
	WIFI_RTMP_MAC \
	RTMP_MAC \
	WIFI_MT_MAC \
	CHIP_MT7603E \
	CHIP_MT7615E \
	MT_MAC \
	RATE_ADAPTION \
	SUPPORT_OPENWRT \
	SDK_USER_LIGHTY \
	MUMIMO_SUPPORT \
	MUMIMO_PLATFORM_PERFORMANCE_LEVEL \
	MU_RA_SUPPORT \
	LED_CONTROL_SUPPORT \
	RA_HW_NAT \
	RA_HW_NAT_WIFI_NEW_ARCH \
	CFG80211_SUPPORT \
	SER_SUPPORT \
	GREENAP_SUPPORT \
	RADIUS_ACCOUNTING_SUPPORT \
	TPC_SUPPORT \
	RLM_CAL_CACHE_SUPPORT \
	CAL_BIN_FILE_SUPPORT \
	RF_LOCKDOWN_SUPPORT \
	PASSPOINT_R2 \
	RED_SUPPORT \
	FIRST_IF_EPAELNA \
	FIRST_IF_IPAILNA \
	FIRST_IF_IPAELNA \
	FIRST_IF_EPAILNA \
	SECOND_IF_EPAELNA \
	SECOND_IF_IPAILNA \
	SECOND_IF_IPAELNA \
	SECOND_IF_EPAILNA \
	THIRD_IF_EPAELNA \
	THIRD_IF_IPAILNA \
	THIRD_IF_IPAELNA \
	THIRD_IF_EPAILNA \
	WIFI_PKT_FWD \
	DOT11K_RRM_SUPPORT \
	DOT11R_FT_SUPPORT \
	ENTERPRISE_AP_SUPPORT \
	MLME_MULTI_QUEUE_SUPPORT\
	DYNAMIC_WMM_SUPPORT \
	WIFI_EAP_FEATURE \
	VLAN_SUPPORT \
	TXRX_STAT_SUPPORT \
	SNIFFER_SUPPORT \
	ANTENNA_CONTROL_SUPPORT \
	MGMT_TXPWR_CTRL \
	RA_PHY_RATE_SUPPORT \
	AMPDU_CONF_SUPPORT \
	ACK_CTS_TIMEOUT_SUPPORT \
	RADIUS_MAC_AUTH_SUPPORT \
	DYNAMIC_VLAN_SUPPORT \
	CUSTOMISED_HOSTAPD_SUPPORT \
	HOSTAPD_WPA3_SUPPORT \
	HOSTAPD_WPA3R3_SUPPORT \
	APCLI_STA_SUPPORT \
	WDS_STA_SUPPORT \
	MBSS_AS_WDS_AP_SUPPORT \
	MBO_SUPPORT \
	MAP_SUPPORT \
	MAP_R2_VER_SUPPORT \
	QOS_R1_SUPPORT \
	WPA3_SUPPORT \
	DPP_SUPPORT \
	OWE_SUPPORT \
	WIFI_PKT_FWD_V1 \
	FIRST_IF_MT7615E \
	FIRST_IF_MT7622 \
	FIRST_IF_MT7626 \
	FIRST_IF_AXE \
	FIRST_IF_MT7915 \
	FIRST_IF_MT7916 \
	SECOND_IF_MT7915 \
	SECOND_IF_MT7916 \
	SECOND_IF_MT7615E \
	SECOND_IF_AXE \
	THIRD_IF_NONE \
	THIRD_IF_MT7615E \
	THIRD_IF_MT7915 \
	THIRD_IF_MT7916 \
	CHIP_AXE \
	CHIP_MT7915 \
	CHIP_MT7916 \
	RT_THIRD_CARD \
	RT_THIRD_IF_RF_OFFSET \
	THIRD_IF_EEPROM_FLASH \
	THIRD_IF_EEPROM_PROM \
	THIRD_IF_EEPROM_EFUSE \
	RT_THIRD_CARD_EEPROM \
	SPECTRUM_SUPPORT \
	MULTI_PROFILE_SUPPORT \
	PRE_CAL_TRX_SET1_SUPPORT \
	MWDS \
	CUSTOMER_VENDOR_IE_SUPPORT \
	MCAST_RATE_SPECIFIC \
	WLAN_HOOK \
	COEX_SUPPORT \
	EASY_SETUP_SUPPORT \
	EVENT_NOTIFIER_SUPPORT \
	AIR_MONITOR \
	OFFCHANNEL_SCAN_FEATURE \
	WNM_SUPPORT \
	INTERWORKING \
	LINUX_NET_TXQ_SUPPORT \
	CHIP_MT7622 \
	CHIP_MT7626 \
	MEMORY_SHRINK \
	RPS_EFFICIENCY \
	WHNAT_SUPPORT \
	FAST_NAT_SUPPORT \
	PRE_CAL_TRX_SET2_SUPPORT \
	LINK_TEST_SUPPORT \
	TCP_RACK_SUPPORT \
	FQ_SCH_SUPPORT \
	BRCM_256QAM_SUPPORT \
	VHT_TXBF_2G_EPIGRAM_IE_SUPPORT \
	DSCP_QOS_MAP_SUPPORT \
	DSCP_PRI_SUPPORT \
	PCIE_ASPM_DYM_CTRL_SUPPORT \
	MIN_PHY_RATE_SUPPORT \
	FAST_UP_RATE_SUPPORT \
	VENDOR_FEATURE11_SUPPORT \
	WIFI_TWT_SUPPORT \
	CTXD_MEM_CPY_SUPPORT \
	CTXD_SCATTER_AND_GATHER_SUPPORT \
	SINGLE_SKU \
	WIFI_SYSDVT \
	WIFI_DBG_TXCMD \
	WARP_V2 \
	OCE_SUPPORT\
	WTBL_TDD_SUPPORT\
	PROFILING_SUPPORT\
	HWIFI_SUPPORT\
	6G_SUPPORT\
	BSSMGR_CROSS_MODULE_SUPPORT \
	MT7976_SUPPORT\
	SNIFFER_RADIOTAP_SUPPORT\
	WIFI_FW_BIN_LOAD\
	DBG_ENHANCE\
	MT76XX_COMBO_DUAL_DRIVER_SUPPORT\
	AX8400_COMPATIBLE_SUPPORT

PKG_CONFIG_DEPENDS:=$(foreach c, $(PKG_KCONFIG),$(if $(CONFIG_MTK_MT7915_$c),CONFIG_$(c)))

include $(INCLUDE_DIR)/package.mk


TAR_CMD=$(HOST_TAR) -C $(1)/ $(TAR_OPTIONS)

define KernelPackage/mt7915
  CATEGORY:=MTK Properties
  TITLE:=MTK wifi MT7915 AP driver
  DEPENDS:= +wifi-profile
ifneq ($(CONFIG_MTK_MT7915_FAST_NAT_SUPPORT), )
ifneq ($(CONFIG_NET_MEDIATEK_HNAT), )
  DEPENDS+=+kmod-mediatek_hnat
endif
endif
ifneq ($(CONFIG_MTK_MT7915_WHNAT_SUPPORT), )
ifneq ($(CONFIG_MTK_MT7915_WARP_V2), )
  FILES:=$(PKG_BUILD_DIR)/mt_wifi_ap/$(PKG_NAME)_mt_wifi.ko \
	$(PKG_BUILD_DIR)/mt_wifi/embedded/plug_in/warp_proxy/$(PKG_NAME)_mtk_warp_proxy.ko
  DEPENDS+=+kmod-warp
  AUTOLOAD:=$(call AutoProbe,$(PKG_NAME)_mt_wifi $(PKG_NAME)_mtk_warp_proxy)
else
  FILES:=$(PKG_BUILD_DIR)/mt_wifi_ap/$(PKG_NAME)_mt_wifi.ko \
	$(PKG_BUILD_DIR)/mt_wifi/embedded/plug_in/whnat/$(PKG_NAME)_mt_whnat.ko
  AUTOLOAD:=$(call AutoProbe,$(PKG_NAME)_mt_wifi $(PKG_NAME)_mt_whnat)
endif
else
  FILES:=$(PKG_BUILD_DIR)/mt_wifi_ap/$(PKG_NAME)_mt_wifi.ko
  AUTOLOAD:=$(call AutoProbe,$(PKG_NAME)_mt_wifi)
endif  
  SUBMENU:=Drivers
  MENU:=1
endef

define KernelPackage/mt7915/config
	source "$(SOURCE)/config.in"
endef

#USE_SOURCE_DIR:=$(MTK_WIFI_DIR)/mt7915
USE_SOURCE_BIN_DIR:=$(TOPDIR)/../ko_module/wlan_driver/jedi/bin

define Build/Compile
	$(MAKE) -C "$(LINUX_DIR)" V=1 \
		CROSS_COMPILE="$(TARGET_CROSS)" \
		ARCH="$(LINUX_KARCH)" \
		M="$(PKG_BUILD_DIR)/mt_wifi_ap" \
		LINUX_DIR="$(KERNEL_BUILD_DIR)" \
		$(foreach c, $(PKG_KCONFIG),$(if $(CONFIG_MTK_MT7915_$c),CONFIG_$(c)=$(CONFIG_MTK_MT7915_$(c)))) \
		modules
endef

define KernelPackage/mt7915/install
endef

$(eval $(call KernelPackage,mt7915))
